<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<section class="content-header">
    <h1>
        任务项编辑
    </h1>
</section>
<section class="content">
    <form id="gantForm" role="form"
          enctype="multipart/form-data">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-body">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="proCode">项目编号</label>
                                    <input id="proCode" type="text" name="proCode"  th:value="${proCode}" class="form-control" readonly>
                                </div>
                                <div class="form-group">
                                    <label for="proName">项目名称</label>
                                    <input id="proName" type="text" name="proName" th:value="${proName}" class="form-control" readonly>
                                </div>
                                <div class="form-group">
                                    <label for="deptName">科室</label>
                                    <input id="deptId" type="hidden" name="deptId" th:value="${deptId}">
                                    <input id="deptName" type="text" name="deptName" class="form-control" th:value="${deptName}" readonly>
                                </div>
                                <div class="form-group pull-right">
                                    <button  type="button" id="btn-save"
                                            class="form-group btn btn-info" style="margin-bottom:0px;">保存
                                    </button>
                                </div>
                            </div>
                        </div>
                        <div style="height: 20px;"></div>
                        <div class="row">
                            <div id="hot"></div>
                        </div>
                    </div>
                    <div class="box-footer">
                        <div class="row">
                            <div class="col-md-2">
                                <label>编制人：</label><label th:text="${createName}"></label>
                            </div>
                            <div class="col-md-6">
                                <label></label>
                            </div>
                            <div class="col-md-4">
                                <div class="col-md-2 col-md-offset-7">
                                </div>
                                <!--<div class="col-md-2">
                                    <button shiro:hasPermission="dsn:proTasks:edit" type="button" id="btn-save"
                                            class="btn btn-info file-contract btn-file">保存
                                    </button>
                                </div>-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    /** 历时 */
    function returnDiachronic(startTime, endTime) {

        if (startTime != null && startTime != "" && endTime != null && endTime != "") {
            return js.diffDay(startTime, endTime);
        }
        return "";
    }

    /** 列表数据加载 */
    function loadGantList() {

        js.get({
            url: ctx + "craft/proQuery/gantList",
            data: {proCode: $("#proCode").val()},
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.hot.loadData(result.data.rows);
                }
            }
        });
    }

    $(function () {

        // 根据项目编号取得项目计划数据
        loadGantList();

        var process = function (data) {

            if ($("#proName").val() == "") {
                js.modal.warning("请输入项目编号！");
                $("#proCode").focus();
                return;
            }

            js.post({
                url: ctx + "craft/proQuery/save",
                data: JSON.stringify(data),
                contentType: "application/json",
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        // 根据项目编号取得项目计划数据
                        // loadGantList();
                        location.reload();
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            })
        }

        /**表单加载*/
        js.hot.init({
            element: document.getElementById('hot'),
            data: {},
            formData: ["proCode","deptId","deptName"],
            colHeaders: ['ID',  '负责人', '内容', '开始时间', '结束时间', '历时', '备注'],
            fieldName: ['id',  'taskerName', 'content', 'startTime', 'endTime', 'diachronic', 'remark'],
            height: 740,
            correctFormat: true,
            minSpareRows: 100,
            disableVisualSelection:'area',
            hiddenColumns: {
                columns: [0],
                indicators: true
            },
            callBack: process,
            saveButtonId: $("#btn-save"),
            customChange: function (row, changeName, data) {
                if (changeName === 'startTime' || changeName === 'endTime') {
                    var diachronic = returnDiachronic(data[3], data[4]);
                    js.hot._hot.setDataAtRowProp(row, 'diachronic', diachronic + '');
                }
            },
            columns: [
                {
                    data: 'id',
                    type: 'numeric',
                    width: 40
                },
                {
                    data: 'taskerName',//负责人
                    type: 'text',
                    width: 80
                },
                {
                    data: 'content',//内容
                    type: 'text',
                    width: 250
                },
                {
                    data: 'startTime',//开始时间
                    type: 'date',
                    dateFormat: 'YYYY-MM-DD',
                    correctFormat: true
                },
                {
                    data: 'endTime',//结束时间
                    type: 'date',
                    dateFormat: 'YYYY-MM-DD',
                    correctFormat: true
                },
                {
                    data: 'diachronic',//历时
                    type: 'numeric'
                },
                {
                    data: 'remark',//备注
                    type: 'text',
                    width: 150
                }
            ]
        })
    })

</script>

</body>
</html>